package com.xcc.opendd;

import android.app.Application;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.Handler;
import android.os.PowerManager;


public class AppLive extends Application {
    public static final String DDAppPage = "com.alibaba.android.rimet";
    public Handler handler;
    private static AppLive appLive;

    public static AppLive getInstance() {
        return appLive;
    }

    public void onCreate() {//初始化application
        super.onCreate();
        appLive = this;
        handler = new Handler();
        TakeManage.getInstance();
        System.out.println("--开启Application--");
    }

    private PowerManager.WakeLock wakeLock;
    private KeyguardManager.KeyguardLock lock;

    public void wakeUpAndUnlock() {
        KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        lock = km.newKeyguardLock("unLock");
        //解锁
        lock.disableKeyguard();
        //获取电源管理器对象
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
        wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
        //点亮屏幕
        wakeLock.acquire();
        //释放
    }

    public void releaseUnlock() {
        if (wakeLock != null)
            wakeLock.release();
        wakeLock = null;
        if (lock != null) lock.reenableKeyguard();
        lock = null;
    }
}
